#ifndef FASYS_FASYS_CSERVICE_PUBLISH_MEHTOD_HPP
#define FASYS_FASYS_CSERVICE_PUBLISH_MEHTOD_HPP

#include <fas/adv/json_rpc3/method.hpp>
#include "../ichannels.hpp"
#include "../api/publish_json.hpp"
#include "tags.hpp"

namespace fasys{ namespace cservice{

namespace aa = ::fas::aop;
namespace ap = ::fas::pattern;
namespace ad = ::fas::adv;
namespace ajr = ::fas::adv::json_rpc3;

struct publish_method
{
  const char *name() const { return "publish"; }

  typedef ::fasys::api::publish_json publish_json;
  
  typedef publish_json invoke_notify;
  /*typedef message_json invoke_request;
  typedef message_json invoke_response;
  */

  typedef publish_json call_notify;
  /*typedef message_json call_request;
  typedef message_json call_response;
  */

  typedef publish_json::target request_type;
  typedef publish_json::target response_type;

  template<typename T>
  void clear(T&) { }

  ichannels* channels;

  template<typename T>
  void notify(T& t, request_type& cmd )
  {
    std::cout << "yo!! PUBLISH METHOD" << std::endl;
    channels->publish(cmd);
  }
};

typedef aa::tag_list_n<
  aa::tag<_publish_>,
  aa::gtag< ajr::_gmethod_ >,
  aa::gtag< ad::_cleaner_ >
>::type publish_method_tag_list;

struct publish_method_advice
  : aa::advice<
      publish_method_tag_list,
      ajr::method<publish_method>
    >
{};

}}

#endif
